package com.gopay.common.cps.dao.wallet.activity.impl;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.cps.dao.wallet.activity.WaActivityManageDao;
import com.gopay.common.domain.dps.WaActivityManage;
import com.gopay.common.util.DateUtils;

/**
 * @author ZHOUPENG
 * @date   2017年8月17日 下午3:21:38
 */
@Repository("waActivityManageDao")
public class WaActivityManageDaoImpl extends BaseDAOImpl<WaActivityManage, Serializable> implements WaActivityManageDao {

	@Override
	public List<WaActivityManage> getEffectiveActivity(int activityType) {
		String hql = "from WaActivityManage t where t.activityType=:activityType "
				+ " and t.activityStartTime <=:currtentDate"
				+ " and t.activityEndTime >=:currtentDate"
				+ " order by t.activityStartTime desc";
		Map<String,Object> map = new HashMap<String,Object>();
		Date currtDate=new Date();
		map.put("activityType",activityType);
		map.put("currtentDate",currtDate);
		List<WaActivityManage> waActivityManageList = this.findByHql(hql,map);
		return waActivityManageList!=null?(waActivityManageList.size()>0?waActivityManageList:null):null;
	}
	
	@Override
	public List<WaActivityManage> getEffectiveActivity() {
		String hql = "from WaActivityManage t where 1=1 "
				+ " and t.activityStartTime <=:currtentDate"
				+ " and t.activityEndTime >=:currtentDate"
				+ " order by t.activityStartTime desc";
		Map<String,Object> map = new HashMap<String,Object>();
		Date currtDate=new Date();
		map.put("currtentDate",currtDate);
		List<WaActivityManage> waActivityManageList = this.findByHql(hql,map);
		return waActivityManageList;
	}
	
	@Override
	public List<WaActivityManage> getActivity() {
		String hql = "from WaActivityManage t where 1=1 "
				+ " and (t.activityStartTime >=:currtentDate"
				+ " or (t.activityEndTime >=:currtentDate and t.activityStartTime <=:currtentDate))"
				+ " order by t.activityStartTime desc";
		Map<String,Object> map = new HashMap<String,Object>();
		Date currtDate=new Date();
		map.put("currtentDate",currtDate);
		List<WaActivityManage> waActivityManageList = this.findByHql(hql,map);
		return waActivityManageList.size()==0?null:waActivityManageList;
	}
}
